1 <?php
2  session_start();
3  
if(isset($_SESSION['user']))
4  {
5
6  }
7  
else{
8   echo
"<script>location.href='login.html'</script>";
9  }
10 ?>
11 <!doctype html>
12 <html>
13   <head>
14   <title>Animals </title>
15     <style>
16       body {
17   margin:
0;
18   font-family: Arial, Helvetica, sans-serif;
19   background: #
484848;
20   }
21 .topnav {
22   overflow: hidden;
23   background-color: #4CAF50;
24   height: 70px;
25   border: 3px solid green;
26 }
27
28 .topnav a {
29   
float: left;
30   color: #f2f2f2;
31   text-align: center;
32   padding: 14px 16px;
33   text-decoration: none;
34   font-size: 35px;
35   font-weight: bold;
36
37 }
38
39 .topnav-right {
40   
float: right;
41 }
42 fieldset {
43     background: white;
44     padding: 10px;
45    margin:auto;
46    max-width:593px;
47     box-shadow: 1px 1px 25px rgba(
0, 0, 0, 0.35);
48     border-radius: 10px;
49     border: 6px solid #4CAF50;
50
51
52 }
53       </style>
54 </head>
55 <body>
56   <div
class="topnav">
57             <a
class="active" href="home.html"><img src="ic_add_pet.png"></a>
58             <a href=
"animals.php">Animals</a>
59             <div
class="topnav-right">
60               <a href=
"logout.php">logout</a>
61             </div>
62           </div>
63
64   <form>
65     <button type=
"submit" formaction="animals.php" style="margin:15px;height: 30px;width: 100px;cursor:pointer;border-radius:15px;
66 border: 3px solid green;background-color: #4CAF50;color:#f2f2f2;font-size:17px;"
>
67     Back</button>
68 </form>
69 <form method=
"post" action="animalsadd.php" >
70 <fieldset>
71    <input type=
"text" name="id" placeholder=" Enter pet_id" style="width:100%;height:30px;
72    border: 2px solid #4CAF50; border-radius:3px; background:transparent;"
required >
73     <br><br>
74    <input type=
"text" name="category" placeholder="Enter pet_category" style="width:100%;height:30px;
75    border: 2px solid #4CAF50; border-radius:3px;background:transparent;"
required>
76    <br><br>
77   
78   <input type=
"text" name="breed" placeholder="Enter breed" style="width:100%;height:30px;
79    border: 2px solid #4CAF50; border-radius:3px;background:transparent;"
required>
80   <br><br>
81   <input type=
"number" step=any name="weight" placeholder="Enter weight" style="width:280px;height:30px;
82    border: 2px solid #4CAF50; border-radius:3px;background:transparent;"
min="1" required>
83   
84  <input type=
"number" step=any name="height" placeholder="Enter height" style="width:300px;height:30px;
85    border: 2px solid #4CAF50; border-radius:3px;background:transparent;"
min="15" required>
86   <br><br>
87   <input type=
"number" name="age" placeholder="Enter age" style="width:280px;height:30px;
88    border: 2px solid #4CAF50; border-radius:3px;background:transparent;"
min="1" required>
89  
90   <input type=
"text" name="fur" placeholder="Enter fur" style="width:300px;height:30px;
91    border: 2px solid #4CAF50; border-radius:3px;background:transparent;"
required>
92   <br><br>
93   <input type=
"number" name="cost" placeholder="Enter cost" style="width:100%;height:30px;
94    border: 2px solid #4CAF50; border-radius:3px;background:transparent;"
min="0" required>
95   <br><br>
96   <input type=
"submit" name="submit" value="save" style="width:100%;height:30px;
97    border: 2px solid #4CAF50; border-radius:3px; cursor:pointer;background-color: #4CAF50"
>&ensp;
98   </fieldset>
99 </form>
100 </body>
101 </html>
102 <?php

103 if
(isset($_POST["submit"]))
104 {
105   
// define variables and set to empty values
106 $servername =
"localhost";
107 $username =
"root";
108 $password =
"";
109 $dbname =
"Petshop_management";
110
111 // Create connection

112 $conn =
new mysqli($servername, $username, $password, $dbname);
113 // Check connection

114 if
($conn->connect_error) {
115     die(
"Connection failed: " . $conn->connect_error);
116 }

117 //echo
" CONNECTION ESTABLISHED \r\n";
118 //echo
" INSERTION IN PROCESS";
119 $id = $_POST[
"id"];
120   $category = $_POST[
"category"];
121   $breed= $_POST[
"breed"];
122   $weight = $_POST[
"weight"];
123   $height = $_POST[
"height"];
124   $age = $_POST[
"age"];
125   $fur= $_POST[
"fur"];
126   $cost = $_POST[
"cost"];
127
128
129
130
131 $sql =
"INSERT INTO pets( pet_id,pet_category,cost)
132 VALUES ('$id','$category','$cost');
133 INSERT INTO animals(pet_id,breed,weight,height,age,fur)
134  VALUES('$id','$breed','$weight','$height','$age','$fur')"
;
135 if
($conn->multi_query($sql) == TRUE) {
136   echo
'<div>
137       <h1 style=
"color:#f2f2f2;font-size:20px; font-family: "Roboto", sans-serif;margin:auto;">New record of id='
138       .$id.
' inserted successfully</h1>
139          </div>
';
140 }
else {
141     echo
"Error: " . $sql . "<br>" . $conn->error;
142 }
143
144 $conn->close();
145 }
146
147 ?>


Gõ tìm kiếm nhanh...